1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include<cstdio> #include<algorithm> using namespace std; int Use[11000]; struct data { int l,w; }wood[11000],change[11000]; bool cmp(data a,data b) { if (a.l!=b.l) return (a.l<b.l); return (a.w<b.w); } int main() { int n,x,y,t,T,ans,num; scanf("%d",&T); while (T--) { scanf("%d",&n); for (int i=1;i<=n;i++) { Use[i]=1; scanf("%d%d",&wood[i].l,&wood[i].w); } sort(wood+1,wood+1+n,cmp); x=0;y=0; Use[1]=0; num=1;ans=1; change[1].l=wood[1].l; change[1].w=wood[1].w; while (num<n) { t=1; x=change[1].l; y=change[1].w; for (int i=1;i<=n;i++) if (Use[i]==1) { if ( x<=wood[i].l && y<=wood[i].w ) { num++; x=wood[i].l; y=wood[i].w; Use[i]=0; } else if (t==1) { num++; ans++; Use[i]=0; change[t].l=wood[i].l; change[t].w=wood[i].w; t++; } } } printf("%d\n",ans); } return 0; }
|